<!--头部公共部分-->
{include file="common/header" /}
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a>首页</a>
        <a>系统</a>
        <a href="/admin/System/approval">审批列表</a>
        <a>
          <cite>审批详情</cite></a>
      </span>
	<a class="layui-btn layui-btn-xs layui-btn-small" style="margin-left: 10px;"
	   href="/admin/System/approval" title="返回">返回</a>
	<a class="layui-btn layui-btn-xs layui-btn-small" style="float:right;margin-top: 10px;"
	   href="javascript:location.replace(location.href);" title="刷新">
		<i class="layui-icon layui-icon-refresh"></i> </a>
</div>

<div class="layui-tab layui-tab-card" lay-filter="filter">
	<div class="layui-tab-content" >
		<div class="layui-tab-item layui-show">
			<div id="jiben" class="x-body" class="clear:both;">
				<div class="layui-card">
					<div class="layui-card-header">标题：{$approval.approval_name}</div>
					<div class="layui-card-body">
						提交人：{$approval.user_name}&nbsp; &nbsp; {$approval.approval_time}
					</div>
					<div class="layui-card-body">
						{$approval.content}
					</div>
				</div>
				<!--橙色分割线-->
				<hr class="layui-bg-orange">
				<div class="layui-card-header">审批状态</div>
				{volist name="approval_lists" id="v"}
				<div class="layui-card-body">
					<img src="{$v.img}" style="width: 30px;height: 30px;border-radius:15px;"/>&nbsp; &nbsp;{$v.name}&nbsp; &nbsp;{if $v.status == 2}<i class="layui-icon layui-icon-flag"></i>{/if}&nbsp; &nbsp;{$v.status_text}<br>
					审批意见:&nbsp; &nbsp;{$v.approval_content}
				</div>
				{/volist}
				{if $approval.status == 1}
					{if $approval.type == 3}
					<div style="padding:15px;">
					<form class="layui-form layui-form-pane">
						<div class="layui-form-item">
							<div class="layui-input-block">
								<input type="hidden" name="id" value="{$approval.id}">
								<input class="layui-btn layui-btn-danger" style="width: 100px;" lay-submit lay-filter="cancel" value="撤销" readonly>
							</div>
						</div>
					</form>
				</div>
					{else/}
					<div style="padding:15px;">
						<form class="layui-form layui-form-pane">
							<div class="layui-form-item layui-form-text">
								<label class="layui-form-label">审批意见</label>
								<div class="layui-input-block">
									<textarea name="approval_content" lay-verify="required" placeholder="请输入审批意见" class="layui-textarea"></textarea>
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-input-block">
									<input type="hidden" name="id" value="{$approval.id}">
									<input class="layui-btn layui-btn-normal" style="width: 100px;" lay-submit lay-filter="form" value="审批" readonly>
									<input class="layui-btn layui-btn-danger" style="width: 100px;" lay-submit lay-filter="reject" value="驳回" readonly>
								</div>
							</div>
						</form>
					</div>
					{/if}
				{/if}
			</div>
		</div>
	</div>
</div>
<!--底部公共部分-->
{include file="common/footer" /}
<script>
	layui.use(['element', 'table','jquery','form','layer'], function(){
		let $ = layui.jquery
			,element = layui.element
			,layer = layui.layer
			,form = layui.form;

		//监听提交
		form.on('submit(form)', function (data) {
			let field = data.field;
			field.status = 2;
			let isLoad;
			$.ajax({
				url: '{:url("System/approval_rejection")}',
				method: "post",
				data: field,
				beforeSend: function () {
					isLoad = layer.load(0, {
						shade: false
					}); //0代表加载的风格，支持0-2
				},
				success: function (result) {
					layer.msg(result.msg);
					if (result.code === 1) {
						setTimeout(function () {
							location.reload();
						}, 2000);
					}
				},
				complete: function () {
					layer.close(isLoad)
				},
				error: function (error) {
					console.log(error)
				}
			});
			return false;
		});

		form.on('submit(reject)', function (data) {
			let field = data.field;
			field.status = 3;
			let isLoad;
			$.ajax({
				url: '{:url("System/approval_rejection")}',
				method: "post",
				data: field,
				beforeSend: function () {
					isLoad = layer.load(0, {
						shade: false
					}); //0代表加载的风格，支持0-2
				},
				success: function (result) {
					layer.msg(result.msg);
					if (result.code === 1) {
						setTimeout(function () {
							location.reload();
						}, 2000);
					}
				},
				complete: function () {
					layer.close(isLoad)
				},
				error: function (error) {
					console.log(error)
				}
			});
			return false;
		});

		form.on('submit(cancel)', function (data) {
			let field = data.field;
			field.status = 4;
			let isLoad;
			$.ajax({
				url: '{:url("System/approval_rejection")}',
				method: "post",
				data: field,
				beforeSend: function () {
					isLoad = layer.load(0, {
						shade: false
					}); //0代表加载的风格，支持0-2
				},
				success: function (result) {
					layer.msg(result.msg);
					if (result.code === 1) {
						setTimeout(function () {
							location.reload();
						}, 2000);
					}
				},
				complete: function () {
					layer.close(isLoad)
				},
				error: function (error) {
					console.log(error)
				}
			});
			return false;
		});

	});
</script>